/*
 $Id$

 Copyright (C) 2006-2007 by David Cotton

 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

 You should have received a copy of the GNU General Public License along with
 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package fr.free.jchecs.ai;

import fr.free.jchecs.core.move.Move;
import fr.free.jchecs.core.move.MoveGenerator;

/**
 * AI engine is limited to randomly select one of the possible moves.
 * 
 * @author David Cotton
 */
final class RandomEngine extends AbstractEngine {
	/**
	 * Instantiates a new engine random IA.
	 */
	RandomEngine() {
		super(1, 1, 1);
	}

	/**
	 * Body search of "better" half-move to a state of the chessboard.
	 * 
	 * @param pEtat
	 *            State of the chessboard.
	 * @param pCoups
	 *            List of valid initial movement.
	 * @return Movement found.
	 */
	@Override
	protected Move searchMoveFor(final MoveGenerator pEtat, final Move[] pCoups) {
		assert pEtat != null;

		final int l = pCoups.length;
		assert pCoups.length > 0;
		addHalfmove(l);
		final Move res = pCoups[RANDOMIZER.nextInt(l)];

		assert res != null;
		return res;
	}
}
